import nuke
def deselect():
    for i in nuke.allNodes():
        i.setSelected(False)

def AngledotDown():
    node = nuke.selectedNodes()
    nodeList = []
    for i in node:
        nodeList.insert(0, i)

    nuke.connectNodes(False, False)
    deselect()

    nodeA = nodeList[0]
    nodeB = nodeList[1]

    for certainInput in range(nodeA.inputs()):
        if nodeA.input(certainInput) is nodeB:
            break

    apos = [nodeA.xpos(), nodeA.ypos()]
    bpos = [nodeB.xpos(), nodeB.ypos()]

    aSize = [nodeA.screenWidth(), nodeA.screenHeight()]
    bSize = [nodeB.screenWidth(), nodeB.screenHeight()]

    dot = nuke.createNode('Dot', inpanel=False)
    dot.setXYpos(int(bpos[0]+float(bSize[0])/2.0-float(dot.screenWidth())/2.0), int(apos[1]+float(aSize[1])/2.0-float(dot.screenHeight())/2.0))
    dot.setSelected(False)

    nodeA.setInput(certainInput, dot)
    dot.setInput(0, nodeB)

    deselect()


def AngledotUp():
    node = nuke.selectedNodes()
    nodeList = []
    for i in node:
        nodeList.insert(0, i)

    nuke.connectNodes(False, False)
    deselect()

    nodeA = nodeList[0]
    nodeB = nodeList[1]

    for certainInput in range(nodeA.inputs()):
        if nodeA.input(certainInput) is nodeB:
            break

    apos = [nodeA.xpos(), nodeA.ypos()]
    bpos = [nodeB.xpos(), nodeB.ypos()]

    aSize = [nodeA.screenWidth(), nodeA.screenHeight()]
    bSize = [nodeB.screenWidth(), nodeB.screenHeight()]

    dot = nuke.createNode('Dot', inpanel=False)
    dot.setXYpos(int(apos[0]+float(aSize[0])/2.0-float(dot.screenWidth())/2.0), int(bpos[1]+float(bSize[1])/2.0-float(dot.screenHeight())/2.0))
    dot.setSelected(False)

    nodeA.setInput(certainInput, dot)
    dot.setInput(0, nodeB)

    deselect()